<template>
  <div>
    <!-- 顶部面包屑导航 -->
    <breadcrumb-nav>
      <template v-slot:firstMenu>订单管理</template>
      <template v-slot:secondMenu>订单明细</template>
    </breadcrumb-nav>

    <!-- 卡片视图 -->
    <el-card>
      <el-card class="box-card goods-add" shadow="never">
        <el-button type="text" icon="el-icon-back" @click="$router.back(-1)">返回订单列表</el-button>
        <el-divider direction="vertical"></el-divider>
        <label>订单编号: {{ orderSn }}</label>
      </el-card>
      <el-table class="custom-order-table" :data="goodsList" border stripe>
        <el-table-column label="商品图标">
          <template slot-scope="scope">
            <el-image
              style="height: 80px; width: 120px"
              :src="scope.row.image"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="shopName" label="店铺"></el-table-column>
        <el-table-column prop="goodsName" label="商品名称"></el-table-column>
        <el-table-column prop="create_time" label="创建时间">
          <template slot-scope="scope">{{ scope.row.createTime | dateFormat }}</template>
        </el-table-column>
        <el-table-column prop="number" label="商品数量"></el-table-column>
        <el-table-column prop="price" label="商品价格" width="120px">
          <template slot-scope="scope">{{ scope.row.price | floatFormat }}</template>
        </el-table-column>
        <el-table-column prop="refundNum" label="状态" width="120px">
          <template slot-scope="scope">{{ scope.row.refundNum | formatRefundStatus }}</template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import BreadcrumbNav from '../../common/BreadcrumbNav'
import { getOrderDetail } from '../../../network/order'

export default {
  name: 'OrderDetail',
  components: {
    BreadcrumbNav
  },
  data () {
    return {
      orderSn: '',
      orderId: 0,
      goodsList: [],
      downloadUrlPrefix: ''
    }
  },
  filters: {
    formatRefundStatus (value) {
      if (value > 0) {
        return '已退款'
      } else {
        return '正常'
      }
    }
  },
  created () {
    console.log('this.$route.query.orderId', this.$route.query.orderId)
    console.log('this.$route.query.orderSn', this.$route.query.orderSn)
    this.downloadUrlPrefix = window.g.MEDIA_DOWNLOAD_URL
    this.orderSn = this.$route.query.orderSn
    this.orderId = this.$route.query.orderId
    this.getOrderDetail(this.$route.query.orderId)
  },
  methods: {
    getOrderDetail (orderId) {
      getOrderDetail({ orderId: orderId }).then(res => {
        if (res.status !== 200) {
          return this.alertMessage('获取订单明细失败', 'error')
        }
        this.goodsList = res.data.data.goodsList
        for (const item of this.goodsList) {
          if (item.icon.includes('http')) {
            item.image = item.icon
          } else {
            item.image = this.downloadUrlPrefix + item.icon
          }
        }
        console.log('order detail is:', res.data)
      })
    }
  }
}
</script>

<style scoped>

</style>
